<script setup>
import { ref } from 'vue'
import { onLaunch, onShow, onLoad } from '@dcloudio/uni-app'
//引入API
import { getGuessLikeAPI } from '@/api/home.js'
//引入子组件
import ItemVue from './Item.vue'
//请求数据初始化页面
const guessLikeList = ref([])
const guessLikeListParams = {
  page: 1,
  pageSize: 10,
}
const finish = ref(false)
const getGuessLike = async () => {
  if (finish.value) {
    return
  }
  const res = await getGuessLikeAPI(guessLikeListParams)
  guessLikeList.value.push(...res.result.items)
  if (res.result.pages === guessLikeListParams.page) {
    finish.value = true
  } else {
    guessLikeListParams.page++
  }
}
onLoad(async () => {
  await getGuessLike()
})
const resetData = () => {
  guessLikeListParams.page = 1
  guessLikeListParams.pageSize = 10
  guessLikeList.value = []
  finish.value = false
}
// 暴露方法
defineExpose({
  resetData,
  getMore: getGuessLike,
})
</script>

<template>
  <view>
 
    <view class="item-container">
      <ItemVue
        v-for="(item, index) in guessLikeList"
        :item="item"
        :key="index"
      />
    </view>
  </view>
</template>

<style lang="scss">


.item-container {
  display: flex;
  flex-wrap: wrap;
  padding: 10rpx;

  > * {
    width: 50%;
    box-sizing: border-box;
    padding: 10rpx;
  }
}
</style>
